home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / misc1 / iv26_w30.zip / INTERVIE / STRBROWS.H < prev    next >
C/C++ Source or Header  |  1980-01-03  |  5KB  |  147 lines

  1. /*
  2.  * Copyright (c) 1987, 1988, 1989 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, distribute, and sell this software and its
  5.  * documentation for any purpose is hereby granted without fee, provided
  6.  * that the above copyright notice appear in all copies and that both that
  7.  * copyright notice and this permission notice appear in supporting
  8.  * documentation, and that the name of Stanford not be used in advertising or
  9.  * publicity pertaining to distribution of the software without specific,
  10.  * written prior permission.  Stanford makes no representations about
  11.  * the suitability of this software for any purpose.  It is provided "as is"
  12.  * without express or implied warranty.
  13.  *
  14.  * STANFORD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  15.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  17.  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  18.  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  19.  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
  20.  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  21.  */
  22.  
  23. /*
  24.  * StringBrowser - a Mac minifinder-like object for perusing and choosing 
  25.  * from list of strings.
  26.  */
  27.  
  28. #ifndef strbrowser_h
  29. #define strbrowser_h
  30.  
  31. #include <InterViews/interactor.h>
  32.  
  33. static const char* SBDone = "\r\t\007\033";
  34.  
  35. static const char SBFirstString = 'g';
  36. static const char SBLastString = 'G';
  37. static const char SBSelectAll = 'a';
  38. static const char SBUnselectAll = '\177';
  39. static const char SBUnselectAllAlt = '\010';
  40. static const char SBSelectPreviousString = 'p';
  41. static const char SBSelectNextString = 'n';
  42. static const char SBSelectTopString = '<';
  43. static const char SBSelectBottomString = '>';
  44. static const char SBScrollDown = 'j';
  45. static const char SBScrollUp = 'k';
  46. static const char SBPageDown = ' ';
  47. static const char SBPageUp = 'b';
  48. static const char SBHalfPageDown = 'd';
  49. static const char SBHalfPageUp = 'u';
  50.  
  51. class ButtonState;
  52. class TextDisplay;
  53.  
  54. class StringBrowser : public Interactor {
  55. public:
  56.     StringBrowser(
  57.         ButtonState*, int rows, int cols, 
  58.         boolean uniqueSel = true, int highlight = Reversed,
  59.         const char* done = SBDone
  60.     );
  61.     StringBrowser(
  62.         const char* name, ButtonState*, int, int,
  63.         boolean = true, int = Reversed, const char* = SBDone
  64.     );
  65.     virtual ~StringBrowser();
  66.  
  67.     void Browse();
  68.     void Insert(const char*, int index);
  69.     void Append(const char*);
  70.     void Remove(int index);
  71.  
  72.     int Index(const char*);
  73.     char* String(int);
  74.     int Count();
  75.     void Clear();
  76.  
  77.     void Select(int index);
  78.     void SelectAll();
  79.     void Unselect(int index);
  80.     void UnselectAll();
  81.     int Selection(int selindex = 0);
  82.     int SelectionIndex(int index);
  83.     int Selections();
  84.     boolean Selected(int index);
  85.  
  86.     virtual void Handle(Event&);
  87.     virtual void Adjust(Perspective&);
  88. protected:
  89.     void Select(int dot, int mark);
  90.     void Unselect(int dot, int mark);
  91.     void ScrollBy(int, int);
  92.     void ScrollBy(int lines);
  93.     void ScrollTo(int, int);
  94.     void ScrollTo(int index);
  95.     void ScrollToView(Coord, Coord);
  96.     void GrabScroll(Event&);
  97.     void RateScroll(Event&);
  98.  
  99.     int Locate(Coord, Coord);
  100.     boolean DoubleClicked(Event&);
  101.  
  102.     virtual boolean HandleChar(char);
  103.     virtual boolean LeftButtonDown(Event&);
  104.  
  105.     virtual void Reconfig();
  106.     virtual void Redraw(Coord, Coord, Coord, Coord);
  107.     virtual void Resize();
  108. protected:
  109.     int rows;
  110.     int columns;
  111.     boolean uniqueSel;
  112.     boolean singleClick;
  113.     int clickDelay;
  114.     int highlight;
  115.     ButtonState* subject;
  116.     const char* done;
  117. private:
  118.     void Init(ButtonState*, int, int, boolean, int, const char*);
  119.     void InitTextDisplay();
  120.     void UpdateSelection(int dot, int mark, int style);
  121.     void Note(Event&);
  122.  
  123.     boolean HandleDownEvent(Event&);
  124.     boolean HandleKeyEvent(Event&);
  125. private:
  126.     char** strbuf;
  127.     int strbufsize;
  128.     int strcount;
  129.     char** selbuf;
  130.     int selbufsize;
  131.     int selcount;
  132.  
  133.     TextDisplay* display;
  134.     int lineheight;
  135.     unsigned long lasttime;
  136.     Coord lastx, lasty;
  137.     int lastdot, lastmark;
  138.     boolean firstResize;
  139. };
  140.  
  141. inline void StringBrowser::Append (const char* s) { Insert(s, strcount); }
  142. inline int StringBrowser::Count () { return strcount; }
  143. inline int StringBrowser::Selections () { return selcount; }
  144. inline boolean StringBrowser::Selected (int i) {return SelectionIndex(i) >= 0;}
  145.  
  146. #endif
  147.